package cn.edu.lingnan.service;

import cn.edu.lingnan.dao.IParticipationDao;
import cn.edu.lingnan.dao.ParticipationDao;
import cn.edu.lingnan.pojo.Participation;

import java.util.List;

public class IParticipationService implements ParticipationService{
    ParticipationDao participationDao = new IParticipationDao();

    @Override
    public boolean updateRank(int sid, String cName,int rank) {
        return participationDao.updateRank(sid,cName,rank);
    }

    @Override
    public List<Participation> findParticipationByNameStatus(String name) {
        return participationDao.findParticipationByNameStatus(name);
    }

    @Override
    public boolean addParticipation(int student_id, int competition_id, String competition_name) {
        int result= participationDao.addParticipation(student_id,competition_id,competition_name);
        if(result==1){
            System.out.println("参加成功！");
            return true;//添加成功
        } else{
            System.out.println("参加失败！");
            return false;//添加失败
        }
    }

    @Override
    public boolean findParticipationById(int id) {
        Participation p=participationDao.findParticipationById(id);

        if(p!=null){
            System.out.println(p);
            return true;
        }else {
            System.out.println("查找失败！");
            return false;
        }
    }

    @Override
    public List<Participation> findParticipationBySid(int sid) {
         return participationDao.findParticipationBySid(sid);

    }

    @Override
    public List<Participation> findParticipationAll() {
        return participationDao.findParticipationAll();
    }

    @Override
    public boolean delParticipation(int id) {
        return participationDao.delParticipation(id);
    }

    @Override
    public boolean updateParticipation(Participation pt) {
        int flag = participationDao.updateParticipation(pt);
        if(flag>0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public List<Participation> findParticipationByName(String name) {
        return participationDao.findParticipationByName(name);
    }

    @Override
    public boolean updateScore(int pid, int score) {
        return participationDao.updateScore(pid,score);
    }
}
